//
//  ChannelDetailCell.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/7/25.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "ChannelDetailCell.h"

@interface ChannelDetailCell ()

@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UIImageView *bgView;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UIButton *collectionBtn;
@property (nonatomic, strong) UIButton *commentBtn;
@property (nonatomic, strong) UIButton *shareBtn;

@property (nonatomic, strong) UIImageView *headView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *noteLabel;
@property (nonatomic, strong) UIButton *videoBtn;

@end

@implementation ChannelDetailCell

+ (ChannelDetailCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"ChannelDetailCell";
    ChannelDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ChannelDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    self.headView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(20), ScreenX375(37), ScreenX375(37))];
    self.headView.clipsToBounds = YES;
    self.headView.layer.cornerRadius = ScreenX375(18.5);
    self.headView.image = ImageWithName(@"头像1");
    [self addSubview:self.headView];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(63), ScreenX375(22), ScreenX375(150), ScreenX375(16))];
    self.nameLabel.textColor = FONTCOLOR_BLACK;
    self.nameLabel.font = KBlodfont(14);
    self.nameLabel.text = @"Makeup行走天涯";
    [self addSubview:self.nameLabel];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(166), ScreenX375(23), ScreenX375(150), ScreenX375(14))];
    self.timeLabel.textColor = REXADECIMALCOLOR(@"#888888");
    self.timeLabel.font = Kfont(12);
    self.timeLabel.textAlignment = NSTextAlignmentRight;
    self.timeLabel.text = @"10小时前";
    [self addSubview:self.timeLabel];
    
    self.noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(63), ScreenX375(44), ScreenX375(200), ScreenX375(14))];
    self.noteLabel.textColor = REXADECIMALCOLOR(@"#888888");
    self.noteLabel.font = Kfont(12);
    self.noteLabel.text = @"行走的设计师，只为给您最好的";
    [self addSubview:self.noteLabel];
    
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(64), SCREEN_WIDTH - ScreenX375(32), ScreenX375(32))];
    self.contentLabel.text = @"英伦室内机房你上课会计师的烦恼";
    self.contentLabel.textColor = REXADECIMALCOLOR(@"#333333");
    self.contentLabel.font = Kfont(15);
    [self addSubview:self.contentLabel];
    
    self.bgView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(98), (SCREEN_WIDTH - ScreenX375(32)), ScreenX375(186))];
    self.bgView.image = [UIImage imageNamed:@"图层57"];
    self.bgView.contentMode = UIViewContentModeScaleAspectFill;
    self.bgView.layer.cornerRadius = ScreenX375(6);
    self.bgView.clipsToBounds = YES;
    [self addSubview:self.bgView];
    
    self.videoBtn = [[UIButton alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - ScreenX375(50)) / 2, ScreenX375(98) + ScreenX375(68), ScreenX375(50), ScreenX375(50))];
    [self.videoBtn setImage:ImageWithName(@"Group 9") forState:UIControlStateNormal];
    [self.videoBtn addTarget:self action:@selector(playVideo) forControlEvents:UIControlEventTouchUpInside];
    self.videoBtn.hidden = YES;
    [self addSubview:self.videoBtn];
    
    self.collectionBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(19), ScreenX375(300), ScreenX375(60), ScreenX375(18))];
    [self.collectionBtn setImage:ImageWithName(@"点赞") forState:UIControlStateNormal];
    [self.collectionBtn setTitle:@" 665" forState:UIControlStateNormal];
    [self.collectionBtn setTitleColor:FONTCOLOR_GRAY forState:UIControlStateNormal];
    self.collectionBtn.titleLabel.font = Kfont(14);
    self.collectionBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.collectionBtn addTarget:self action:@selector(appraiseAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.collectionBtn];
    
    self.commentBtn = [[UIButton alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - ScreenX375(60)) / 2, ScreenX375(300), ScreenX375(60), ScreenX375(18))];
    [self.commentBtn setImage:ImageWithName(@"评论 copy 2") forState:UIControlStateNormal];
    [self.commentBtn setTitle:@" 26" forState:UIControlStateNormal];
    [self.commentBtn setTitleColor:FONTCOLOR_GRAY forState:UIControlStateNormal];
    self.commentBtn.titleLabel.font = Kfont(14);
    self.commentBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [self.commentBtn addTarget:self action:@selector(commentAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.commentBtn];
    
    self.shareBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(79), ScreenX375(300), ScreenX375(60), ScreenX375(18))];
    [self.shareBtn setImage:ImageWithName(@"转发") forState:UIControlStateNormal];
    [self.shareBtn setTitle:@" 19" forState:UIControlStateNormal];
    [self.shareBtn setTitleColor:FONTCOLOR_GRAY forState:UIControlStateNormal];
    self.shareBtn.titleLabel.font = Kfont(14);
    self.shareBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.shareBtn addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.shareBtn];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(340) - 1, SCREEN_WIDTH - ScreenX375(32), 1)];
    line.backgroundColor = REXADECIMALCOLOR(@"#f2f2f2");
    [self addSubview:line];
}

- (void)setChannelListModel:(ChannelListModel *)channelListModel {
    _channelListModel = channelListModel;
    
    [self.bgView sd_setImageWithURL:[NSURL URLWithString:channelListModel.pic] placeholderImage:nil options:SDWebImageRetryFailed];
    
    [self.collectionBtn setTitle:[NSString stringWithFormat:@"  %@",channelListModel.zanNum] forState:UIControlStateNormal];
    [self.commentBtn setTitle:[NSString stringWithFormat:@"  %@",channelListModel.appraiseNum] forState:UIControlStateNormal];
    [self.shareBtn setTitle:[NSString stringWithFormat:@"  %@",channelListModel.shareNum] forState:UIControlStateNormal];
    self.nameLabel.text = channelListModel.userName;
    self.noteLabel.text = [NSString stringWithFormat:@"%@·%@·%@·%@",channelListModel.sex,channelListModel.ages,channelListModel.season,channelListModel.type];
    self.contentLabel.text = channelListModel.proName;
    if (channelListModel.coverPics.count > 0) {
        [self.bgView sd_setImageWithURL:[NSURL URLWithString:channelListModel.coverPics[0]] placeholderImage:nil options:SDWebImageRetryFailed];
    }
    [self.headView sd_setImageWithURL:[NSURL URLWithString:channelListModel.userPic] placeholderImage:nil options:SDWebImageRetryFailed];
    self.timeLabel.text = [HttpManager getTime:[HttpManager TimeStamp:channelListModel.createTime]];
    
    if ([channelListModel.isZan integerValue] == 1) {
        [self.collectionBtn setImage:ImageWithName(@"已点赞") forState:UIControlStateNormal];
    }else {
        [self.collectionBtn setImage:ImageWithName(@"点赞") forState:UIControlStateNormal];
    }
    
    if (channelListModel.videoUrl.length > 0) {
        self.videoBtn.hidden = NO;
    }else {
        self.videoBtn.hidden = YES;
    }
}

- (void)appraiseAction {
    if (_appraiseClick) {
        _appraiseClick();
    }
}

- (void)commentAction {
    if (_commentClick) {
        _commentClick();
    }
}

- (void)shareAction {
    if (_shareClick) {
        _shareClick();
    }
}

- (void)playVideo {
    if (_playClick) {
        _playClick();
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@implementation ChannelListModel

+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"Id": @"id"
                                                                  }];
}

@end
